package com.linkturing.swing;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.linkturing.util.Constants;
import com.linkturing.util.JedisUtil;

import cn.hutool.core.util.StrUtil;

public class SetPwdSwing extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					SetPwdSwing frame = new SetPwdSwing();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SetPwdSwing() {
		frame = this;
		//设置加重维护密码
		setTitle("\u8BBE\u7F6E\u52A0\u91CD\u7EF4\u62A4\u5BC6\u7801");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 395, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		//密码：
		JLabel lblNewLabel = new JLabel("\u5BC6\u7801\uFF1A");
		lblNewLabel.setBounds(42, 86, 53, 31);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(126, 83, 119, 38);
		contentPane.add(textField);
		textField.setColumns(10);

		//确定
		JButton btnNewButton = new JButton("\u786E\u5B9A");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if(StrUtil.isBlank(textField.getText())) {
					JOptionPane.showMessageDialog(frame, "请输入密码！");return;
				}
				JedisUtil.set(Constants.addweight_pwd, textField.getText());
				frame.dispose();
			}
		});
		btnNewButton.setBounds(126, 171, 119, 31);
		contentPane.add(btnNewButton);
	}

}
